{include file='header.html'}
<link type="text/css" href="../../page/css/delay.css" rel="stylesheet">
<link type="text/css" href="{$common_domain}/tools/datepicker/jquery.ui.theme.css" rel="stylesheet" />
<link type="text/css" href="{$common_domain}/tools/datepicker/jquery.ui.datepicker.css" rel="stylesheet" />
<link type="text/css" href="{$common_domain}/tools/datepicker/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery-1.7.2.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.core.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.widget.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/DateTimePicker.js"></script>
<script type="text/javascript">

$(function () {

    $("#app_date").datepicker({
        onClose: function(year, month, inst){
            check_date();
        }
    });
    var url = window.location.href;

    function check_date(){
        var app_date = $("#app_date").val();
        var start_time = app_date+' '+$('#s_time').val();
        var end_time = app_date+' '+$('#e_time').val();
        if( app_date == '' ){
            return false;
        }else{
            $.post('{$baseurl}/askleave/',{ start:start_time,end:end_time,'type':'公出',cal:'long',istrip:0},function (data) {
                if(data.is_ever == 1){
                    $("#days").val(0);
                    alert("您在"+data.start_time+"至"+data.end_time+"已经申请了"+data.type);
                    return false;
                }else{
                    $("#days").val(data.day);
                    if(data.day == 0){
                        alert("该时间不能公出");
                        return false;
                    }else{
                        return true;
                    }
                }
            },'json');
        }
    }

    $("form:first").submit(function(){
        //如果是上传图片使用
        var is_up_file = $('#is_up_file').val();
        if(is_up_file=='1'){
            return true;
        }
        if(confirm("确定提交吗?")){
            var app_date = $("#app_date").val();
            var desc = $("#desc").val();
            if( app_date == ''){
                alert('请填写公出日期');
                return false;
            } else if(desc == '') {
                alert('公出必须填写Note!');
                return false;
            }else{
                return check_date();
            }
        }
        else{
            return false;
        }
    }
    );

});
function check(){
    var app_date = $("#app_date").val();
    if(app_date==""){
        $('#s_time').val("09:00");
        $("#app_date").focus();
        return false;
    }
    var start_time = $('#s_time').val();
    var end_time = $('#e_time').val();
    var start = parseInt(start_time.substr(0,2));
    var end = parseInt(end_time.substr(0,2));
    if(start>=end){
        alert('结束时间应大于开始时间');
        $('#s_time').val("09:00");
        return false;
    }
    return true;
}
var KQUpload = {
        checkFileExt: function(filename){
               var allow_ext = new  Array('.jpg','.jpeg','.gif');
               var ext = filename.substr(filename.lastIndexOf(".")).toLowerCase();
               if(allow_ext.indexOf(ext) != -1){  return true; }
               return false;
            },
        upload_img: function(){
            $("#frmAsk").attr("action", "/ajaxupload/");
            $("#frmAsk").attr("target",'upload_frame');
            $("#frmAsk").submit();
            $("#frmAsk").attr("action", "");
            $("#frmAsk").attr("target",'');
        },
        del_img:function(){
            $('#need_img_li').hide();
            $('#need_img').attr('src','');
            $('#need_img_a').attr('href','');
            $('#img_file').val('');
            $('#is_up_file').val(0);
        }
    };
    $(document).ready(function(){
        $('#photo_up').change(function(){
            if(!KQUpload.checkFileExt(this.value)){
                alert('您上传的图片类型不符合规则！请重新上传');
                return false;
             }else{
                 $('#is_up_file').val(1);
                 KQUpload.upload_img();
             }
        });
    });
</script>
<div id="content">
    <i class="con_l">&nbsp;</i> <i class="con_r">&nbsp;</i>
    <div class="main">
        <div class="blank"></div>

        <form id="frmAsk" action="" method="post" enctype="multipart/form-data">
        <input type="hidden" id="is_corptrip" name="is_corptrip" value="1">
            <ul class="ul_cc">
            <li class="s">
                <b class="li_b">日期</b>
                <!-- <input id = "start_time"  name="start_time" readonly = "readonly" type="text" value="" class="jko"/>
                至
                <input id = "end_time"   name="end_time" readonly = "readonly" type="text" value="" class="jko"/> -->
                <input id = "app_date"   name="app_date" readonly = "readonly" type="text" value="{if $fd}{$fd}{/if}" class="jko"/>
                &nbsp;&nbsp;
                <select name="start_time" id="s_time"  onchange="check()">
                <option value="09:00" {if $fd_s == '09:00'}selected{/if}>09:00</option>
                <option value="10:00">10:00</option><option value="11:00">11:00</option>
                <option value="12:00">12:00</option><option value="13:00">13:00</option>
                <option value="14:00" {if $fd_s == '14:00'}selected{/if}>14:00</option>
                <option value="15:00">15:00</option><option value="16:00">16:00</option>
                <option value="17:00">17:00</option>
                </select>至
                <select name="end_time" id="e_time" onchange="check()">
                <option value="10:00">10:00</option><option value="11:00">11:00</option>
                <option value="12:00">12:00</option><option value="13:00">13:00</option>
                <option value="14:00" {if $fd_e == '14:00'}selected{/if}>14:00</option>
                <option value="15:00">15:00</option><option value="16:00">16:00</option>
                <option value="17:00">17:00</option>
                <option value="18:00" {if $fd_e != '14:00'}selected{/if}>18:00</option>
                </select>
            <li>

            <li class="s" style="display:none;">
                <b class="li_b">天数</b>
                <input name="days" id ="days"  style="width:50px;text-align:center" type="text" value="0"  />天
            <li>


            <li class="s" id="upfile">
                <b class="li_b">图片(文件大小<2M,支持格式jpg/gif)</b>
                <a id="" href="javascript:;" class="tian_one_span">
                  上传证明
                                  <input id="photo_up" class="vis2op" type="file" hidefocus="hidefocus" name="file">
                                </a>
            <li>
            <li class="s" style="display:none" id="need_img_li">
            <input type="hidden" name="is_up_file" id="is_up_file" value="0">
            <input type="hidden" name="img_file" id="img_file" value="">
            <a href="" target="_blank" id="need_img_a" title="点击查看大图"><img id="need_img" width="240" height="180"></a>&nbsp;<a href="javascript:void(0);" onclick="KQUpload.del_img()" style="margin:0 0 0 10px;">删除</a>
            </li>
            <li class="s">
                <b class="li_b">审批人：{$audit_users.1}</b>
            <li>

            <li class="s">
                <b class="li_b">Note:</b>
                <textarea name = "desc" rows="5" cols="30" style="width:668px; border:1px solid #bdbdbd;" id="desc"></textarea>
            <li>

            <li class="s"><input type="submit" class="lgo" value="提交申请"></li>
            </ul>

        </form>

    </div>
</div>
<iframe name="upload_frame" id="upload_frame" style="width:0;height:0;display:none;" ></iframe>
{include file='footer.html'}
